package com.fenghongzhang.new1803a;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.app.DatePickerDialog;
import android.app.ProgressDialog;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TimePicker;
import android.widget.Toast;

import java.util.Calendar;

public class MainActivity extends AppCompatActivity {

    private AlertDialog alertDialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void btn1(View view) {

        //new
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

//        builder.setIcon(R.mipmap.ic_launcher).setMessage("呵呵");
        builder.setIcon(R.mipmap.ic_launcher);
        builder.setMessage("提示内容");
        builder.setTitle("标题");

        builder.setPositiveButton("ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this, "点了确认", Toast.LENGTH_SHORT).show();
            }
        });

        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this, "点了取消", Toast.LENGTH_SHORT).show();
            }
        });

//        //创建出对话框
        AlertDialog alertDialog = builder.create();
//
        alertDialog.show();


        ProgressDialog progressDialog = new ProgressDialog(this,2);


    }

    public void btn2(View view) {
        //new
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setIcon(R.mipmap.ic_launcher);
        builder.setTitle("标题");

        builder.setPositiveButton("ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this, "点了确认", Toast.LENGTH_SHORT).show();
            }
        });

        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this, "点了取消", Toast.LENGTH_SHORT).show();
            }
        });

        final String[] s = new String[]{"李白","韩信","阿珂"};
        //单选内容
        builder.setSingleChoiceItems(s, 0, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this, s[which], Toast.LENGTH_SHORT).show();
            }
        });

//        //创建出对话框
        AlertDialog alertDialog = builder.create();
//
        alertDialog.show();
    }

    public void btn3(View view) {

        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setIcon(R.mipmap.ic_launcher);
        builder.setTitle("标题");

        builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this, "确认", Toast.LENGTH_SHORT).show();
            }
        });

        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this, "取消", Toast.LENGTH_SHORT).show();
            }
        });


        //1 setMesssage
        //2,setsiglen
        //3,setMulti

        String[] strings = new String[]{"男人","女人","中性"};
        final boolean[] booleans = new boolean[]{true,true,false};
        builder.setMultiChoiceItems(strings, booleans, new DialogInterface.OnMultiChoiceClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                booleans[which] = isChecked;
            }
        });


        AlertDialog alertDialog = builder.create();
        alertDialog.show();

    }

    public void btn4(View view) {

        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setIcon(R.mipmap.ic_launcher);
        builder.setTitle("标题");

        View inflate = LayoutInflater.from(this).inflate(R.layout.dialog_layout, null);

        ImageView viewById = inflate.findViewById(R.id.img);
        viewById.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //取消对话框
                alertDialog.dismiss();
            }
        });
        builder.setView(inflate);

        alertDialog = builder.create();
        alertDialog.show();


    }

    public void btn5(View view) {
        final ProgressDialog progressDialog = new ProgressDialog(this);

        progressDialog.setMax(100);
        progressDialog.setProgress(50);
        progressDialog.setTitle("标题");
        progressDialog.setMessage("内容");

        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

        progressDialog.setButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                progressDialog.dismiss();
            }
        });

        progressDialog.show();
    }

    public void btn6(View view) {

        //用日历对象,取当前的日期
        Calendar instance = Calendar.getInstance();


        DatePickerDialog datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
                Toast.makeText(MainActivity.this, "年:"+year+"月:"+month+"日"+dayOfMonth, Toast.LENGTH_SHORT).show();
            }
        },instance.get(Calendar.YEAR),instance.get(Calendar.MONTH),instance.get(Calendar.DAY_OF_MONTH));


        datePickerDialog.show();
    }

    public void btn7(View view) {

        Calendar instance = Calendar.getInstance();
        new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                Toast.makeText(MainActivity.this, "小时:"+hourOfDay+"分钟:"+minute, Toast.LENGTH_SHORT).show();
            }
        },instance.get(Calendar.HOUR),instance.get(Calendar.MINUTE),true).show();


    }

    public void btn8(View view) {

        MyDialog myDialog = new MyDialog(this);

        myDialog.setMessageString("呵呵呵呵");
        myDialog.setTitleString("标题222");
        myDialog.setOkString("ok");


        myDialog.setYesonClickListener(new MyDialog.YesOnClickListener() {
            @Override
            public void OnClick() {
                Toast.makeText(MainActivity.this, "哈哈", Toast.LENGTH_SHORT).show();
            }
        });


        myDialog.show();

    }
}
